#!/usr/bin/env bash

# update-long-term-memory
# This program is part of the backup-data program
# update-long-term-memory is a component of the faridayix robot
# intelligence
# Copyright (C) 2009 Scott C. MacCallum
# scottmaccal@gmail.com
# http://code.google.com/p/backup-data/

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# robot: is a variable holding the robots name

# time: is a variable holding the current time +%Y year %M month %d date
# %H hour and %S seconds that the robot is aware of

# printf: print function "text to screen"

# mkdir: make directory -v verbose -p create all directories leading
# up to the given directory that do not exist already. If the given
# directory already exists, ignore the error

# rsync: remote synchronize -v verbose -a archive

# echo: "output this string of characters" >> append to this file

# dmesg: display message

# top: system usage -b batch mode -n number of seconds to run

# ps: processes -e every one -f full listing

# df: disk free -h human readable

# exit: exit program

robot=`hostname`

year=`date +%Y`

month=`date %m`

date=`date %d`

$year_month_date_hour_minute_second=`date +%Y-%m-%d-%H_%M_%S`

# --------------------------------------------
# Update the etcetera data in long term memory
# --------------------------------------------

printf "Updating the etcetera data in long term memory...\n\n"

ssh -v $robot@long-term-memory 'mkdir -v -p /usr/home/$robot/long-term-memory'

ssh -v $robot@long-term-memory 'mkdir -v -p /usr/home/$robot/long-term-memory/$year'

ssh -v $robot@long-term-memory 'mkdir -v -p /usr/home/$robot/long-term-memory/$year/$month'

ssh -v $robot@long-term-memory 'mkdir -v -p /usr/home/$robot/long-term-memory/$year/$month/$date'

rsync -v -a /etc $robot@long-term-memory:/usr/home/$robot/long-term-memory/$year/$month/$date

printf "At $year_month_date_hour_minute_second update of the etcetera data in long term memory was successful.\n\n"

# ---------------------------------------------------------
# Update the variable, name daemon data in long term memory
# ---------------------------------------------------------

#printf "Updating the variable, name daemon data in long term memory...\n\n" 

#rsync -v -a /var/named backup@ipaddress:/usr/home/backup/$robot/daily-update

#printf "At $year_month_date_hour_minute_second update of the /var/named directory from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# ----------------------------------------------------------
# Update the variable, log, directory on the remote computer
# ----------------------------------------------------------

#printf "Updating the variable, log, directory on the remote computer...\n\n"

#rsync -v -a /var/log backup@ipaddress:/usr/home/backup/$robot/daily-update

#printf "At $year_month_date_hour_minute_second update of the /var/log directory from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# -------------------------------------------------------
# Update the user, home, directory on the remote computer
# -------------------------------------------------------

#printf "Updating the user, home, directory on the remote computer...\n\n"

#rsync -v -a /usr/home backup@ipaddress:/usr/home/backup/$robot/daily-update

#printf "At $year_month_date_hour_minute_second update of the /var/log directory from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# ------------------------------------------------
# Update the home directory on the remote computer
# ------------------------------------------------

#printf "Updating the user, home, directory on the remote computer...\n\n"

#rsync -v -a /home backup@ipaddress:/usr/home/backup/$robot/daily-update

#printf "At $year_month_date_hour_minute_second update of the /usr/home directory from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# ------------------------------------------------------------------------
# Update the user, local, binary, daily-update file on the remote computer
# ------------------------------------------------------------------------

#printf "Updating the user, local, binary, daily-update file on the remote computer...\n\n"

#rsync -v -a /usr/local/bin/daily-update backup@ipaddress:/usr/home/backup/$robot/daily-update

#printf "At $year_month_date_hour_minute_second update of the /usr/local/bin/daily-update file from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# -------------------------------------------------------------------------
# Update the user, local, binary, weekly-update file on the remote computer
# -------------------------------------------------------------------------

#printf "Updating the user, local, binary, weekly-update file on the remote computer...\n\n"

#rsync -v -a /usr/local/bin/weekly-update backup@ipaddress:/usr/home/backup/$robot/weekly-update

#printf "At $year_month_date_hour_minute_second update of the /usr/local/bin/weekly-update file from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# ----------------------------------------------------------------------------
# Update the user, local, binary, monthly-snapshot file on the remote computer
# ----------------------------------------------------------------------------

#printf "Updating the user, local, binary, monthly-snapshot file on the remote computer...\n\n"

#rsync -v -a /usr/local/bin/monthly-snapshot backup@ipaddress:/usr/home/backup/$robot/daily-update

#printf "At $year_month_date_hour_minute_second update of the /usr/local/bin/monthly-snapshot file from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# ----------------------------------------------------------------------------------------------
# Update the temporary, backup our data, daily-update, Chronos table file on the remote computer
# ----------------------------------------------------------------------------------------------

#printf "Updating the temporary, backup our data, daily-update, Chronos table file on the remote computer...\n\n"

#crontab -l > /tmp/backup-data/daily-update/crontab

#rsync -v -a /tmp/backup-data/daily-update/crontab backup@ipaddress:/usr/home/backup/$robot/daily-update

#printf "At $year_month_date_hour_minute_second update of the /tmp/backup-data/daily-update/crontab file from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# ----------------------------------------------------------------------------------------------
# Update the temporary, backup our data, daily-update, boot-messages file on the remote computer
# ----------------------------------------------------------------------------------------------

#printf "Updating the temporary, backup our data, daily-update, boot-messages file on the remote computer...\n\n"

#dmesg > /tmp/backup-data/daily-update/boot-messages

#rsync -v -a /tmp/backup-data/daily-update/boot-messages backup@ipaddress:/usr/home/backup/$robot/daily-update

#printf "At $year_month_date_hour_minute_second update of the /tmp/backup-data/daily-update/boot-messages file on $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# ------------------------------------------------------------------------------------------
# Update the temporary, backup our date, daily-update, cpu-usage file on the remote computer
# ------------------------------------------------------------------------------------------

#printf "Updating the temporary, backup our data, daily-update, cpu-usage file on the remote computer...\n\n"

#top -b -n 1 > /tmp/backup-data/daily-update/cpu-usage

#rsync -v -a /tmp/backup-data/daily-update/cpu-usage backup@ipaddress:/usr/home/backup/$robot/daily-update

#printf "At $year_month_date_hour_minute_second update of the /tmp/backup-data/daily-update/cpu-usage file from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# --------------------------------------------------------------------------------------------------
# Update the temporary, backup our data, daily-update, processes-running file on the remote computer
# --------------------------------------------------------------------------------------------------

#printf "Updating the temporary, backup our data, processes-running file on the remote computer...\n\n"

#ps -e -f > /tmp/backup-data/daily-update/processes-running

#rsync -v -a /tmp/backup-data/daily-update/processes-running backup@ipaddress:/usr/home/backup/$robot/daily-update

#printf "At $year_month_date_hour_minute_second update of the /tmp/backup-data/daily-update/processes-running file from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# ------------------------------------------------------------------------------------------------
# Update the temporaryorary, backup our data, daily-update, disk-space file on the remote computer
# ------------------------------------------------------------------------------------------------

#printf "Updating the temporary, backup our data, daily-update, disk-space file...\n\n"

#df -h > /tmp/backup-data/daily-update/disk-space

#rsync -v -a /tmp/backup-data/daily-update/disk-space backup@ipaddress:/usr/home/backup/$robot/daily-update/disk-space

#printf "At $year_month_date_hour_minute_second update of the /tmp/backup-data/daily-update/disk-space file from $robot was successful.\n\n" >> /tmp/backup-data/daily-update/update-log

# ----------------
# Exit the program
# ----------------

exit
# ---End of File---
